package com.ttc.ssm.service.home.impl;

import com.ttc.ssm.mapper.admin.*;
import com.ttc.ssm.mapper.home.HomeDeliveryActivityMapper;
import com.ttc.ssm.mapper.home.HomeDeliveryMapper;
import com.ttc.ssm.mapper.home.HomeInviteActivityMapper;
import com.ttc.ssm.mapper.home.HomeInviteMapper;
import com.ttc.ssm.po.*;
import com.ttc.ssm.service.home.HomeCommonService;
import com.ttc.ssm.service.home.HomeCustomerService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * Created by Jiarui on 2016/8/5.
 */
public class HomeCommonServiceImpl implements HomeCommonService {

    @Autowired
    CityMapper cityMapper;

    @Autowired
    ZoneMapper zoneMapper;

    @Autowired
    IndustryMapper industryMapper;

    @Autowired
    CompanyPropertyMapper companyPropertyMapper;

    @Autowired
    CompanySizeMapper companySizeMapper;

    @Autowired
    HomeDeliveryActivityMapper homeDeliveryActivityMapper;

    @Autowired
    HomeDeliveryMapper homeDeliveryMapper;

    @Autowired
    HomeInviteActivityMapper homeInviteActivityMapper;

    @Autowired
    HomeInviteMapper homeInviteMapper;

    @Override
    public List<City> getCityByZoneId(int zone_id) throws Exception {
        return cityMapper.getCityByZoneId(zone_id);
    }

    @Override
    public List<Zone> getZone() throws Exception {
        return zoneMapper.getZone();
    }

    @Override
    public List<Industry> getIndustry() throws Exception {
        return industryMapper.getIndustry();
    }

    @Override
    public List<CompanyProperty> getCompanyProperty() throws Exception {
        return companyPropertyMapper.getCompanyProperty();
    }

    @Override
    public List<CompanySize> getCompanySize() throws Exception {
        return companySizeMapper.getCompanySize();
    }

    @Override
    public List<City> getAllCity() throws Exception {
        return cityMapper.getAllCity();
    }

    @Override
    public void updateIsRead(Map map) throws Exception {
        homeDeliveryActivityMapper.updateIsRead(map);
    }

    @Override
    public void updateIsReadInvite(Map map) throws Exception {
        homeInviteActivityMapper.updateIsRead(map);
    }

    @Override
    public void updateInviteStatus(Map map) throws Exception {
        homeInviteMapper.updateStatus(map);
    }

    @Override
    public void insertInviteActivity(InviteActivity inviteActivity) throws Exception {
        homeInviteActivityMapper.insertActivity(inviteActivity);
    }

    @Override
    public void insertDeliveryWhenAccept(Delivery delivery) throws Exception {
        homeDeliveryMapper.insertDelivery(delivery);
        DeliveryActivity deliveryActivity = new DeliveryActivity();
        deliveryActivity.setDelivery_id(delivery.getDelivery_id());
        deliveryActivity.setType(1);
        deliveryActivity.setCompany_id(delivery.getCompany_id());
        deliveryActivity.setCustomer_id(delivery.getCustomer_id());
        deliveryActivity.setStatus(delivery.getStatus());
        deliveryActivity.setIs_read(1);
        deliveryActivity.setDate_added(delivery.getDate_added());
        homeDeliveryActivityMapper.insertActivity(deliveryActivity);
    }

}
